package com.ysd.repository;

import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ysd.entity.UserInfo;

public interface UserInfoRepository extends JpaRepository<UserInfo, String>,JpaSpecificationExecutor<UserInfo> {
	//登录就是查看数据库中是否有这个用户
		UserInfo findByUname(String uname);
		
		//重置密码
		@Query(value = "UPDATE user set passcheck ='admin' WHERE uid=?1",nativeQuery = true)  
		@Modifying
		@Transactional
		Integer ResetPasscheck(String uid);
		/**
		 * 验证用户名
		 * @param uname
		 * @return
		 */
		@Modifying
		@Transactional
		@Query(value = "SELECT * FROM User WHERE uname=?1" ,nativeQuery = true)
		UserInfo pduname(String uname);


		/**
		 * 向中间表添加角色和用户的
		 * @param userid
		 * @param roleid
		 */
		@Modifying
		@Query(value = "insert into user_roles VALUES(?1,?2)", nativeQuery = true)
		@Transactional
		void saveUserrole(String uid, String rid);

		/**
		 * 删除角色
		 * @param uId
		 * @param rId
		 */
		@Modifying
		@Query(value = "delete from user_roles where uid = ?1 and rid = ?2", nativeQuery = true)
		@Transactional
		void delUserrole(String uid, String rid);

}
